package com.googlecode.yoohoo.xmppcore.protocol.stream.error;

import com.googlecode.yoohoo.xmppcore.protocol.AbstractError;
import com.googlecode.yoohoo.xmppcore.protocol.parsing.IXmppParsingFactory;
import com.googlecode.yoohoo.xmppcore.protocol.parsing.ProtocolKey;
import com.googlecode.yoohoo.xmppcore.protocol.translation.IXmlWriter;

public class StreamError extends AbstractError {
	public static final String NAMESPACE_STREAM_ERROR = "urn:ietf:params:xml:ns:xmpp-streams";
	
	public static final ProtocolKey PROTOCOL_KEY = new ProtocolKey("error", IXmppParsingFactory.NAMESPACE_STREAM);
	public static final ProtocolKey PROTOCOL_KEY_ERROR_DETAIL = new ProtocolKey(NAMESPACE_STREAM_ERROR);

	public StreamError() {
	}
	
	public StreamError(String definedCondition) {
		super(definedCondition);
	}

	// (rfc3290 4.7.1)
	// stream error is always unrecoverable
	@Override
	public final boolean shouldCloseStream() {
		return true;
	}

	@Override
	protected String getDefinedConditionNamespace() {
		return NAMESPACE_STREAM_ERROR;
	}

	@Override
	protected void writeErrorHeader(IXmlWriter writer) {
		writer.writeStartElement("stream", "error");
	}

	@Override
	protected void writeErrorFooter(IXmlWriter writer) {
		writer.writeEndElement();
	}
}
